package yb.ecp.fast.infra.bus;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

@Component
public class MessageTask {
    public static final BlockingQueue<String> q = new LinkedBlockingQueue<String>();

    @PostConstruct
    public void plusLf() {
        Timer t = new Timer();
        t.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                if (!q.isEmpty()) {

                    try {
                        String s = q.take();
                        System.out.println("处理消息。。。。。" + s);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        }, 100, 1000);

    }
}
